// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import axios from 'axios'
import router from './router'
import "lib-flexible"
import moment from 'moment'
import Vant from 'vant'
import 'vant/lib/index.css'
import * as dd from 'dingtalk-jsapi'
import VueWechatTitle from 'vue-wechat-title'
// import 'es6-promise/auto'

Vue.use(Vant)
Vue.use(VueWechatTitle)
Vue.prototype.$moment = moment
Vue.prototype.$http = axios
Vue.prototype.$dd = dd
Vue.config.productionTip = false

// import VConsole from "vconsole"
// const vConsole = new VConsole()

let jsApiList = ['device.base.getInterface', 'device.base.getWifiStatus', 'device.connection.getNetworkType', 'device.notification.confirm', 'biz.contact.choose', 'biz.contact.complexPicker']

// 签名
//axios.get("/api/auth/getPcJsConfig").then(res => {
axios.get("/api/auth/getMobJsConfig").then(res => {
    console.log('签名okkkk');
    sessionStorage.setItem("corpId", res.data.corpId)
    res.data.jsApiList = jsApiList;
    //免登
    dd.ready(function() {
        dd.runtime.permission.requestAuthCode({
            corpId: res.data.corpId, // 企业id
            onSuccess: function(result) {
                //code 给服务端
                let params = { code: result.code };
                axios.get("/api/auth/login", { params: params }).then(res => {
                    console.log('免登okkkk');
                    if (res.data.code == 0) {
                        // 获取角色
                        let role = ['0'];
                        res.data.user.roles.forEach(el => {
                            role.push(el.name);
                        });
                        sessionStorage.setItem('role', JSON.stringify(role));
                        sessionStorage.setItem("deptID", JSON.stringify(res.data.user.deptInfo)) //申请人所在ID
                        sessionStorage.setItem('userId', res.data.user.userid) //申请人userid
                        axios.defaults.headers.common['Authorization'] = res.data.token // 请求头文件
                        new Vue({
                            el: '#app',
                            router,
                            components: { App },
                            template: '<App/>'
                        })

                    } else {
                        console.log('免登失败')
                    }

                })
            },
        })
        dd.config(res.data)
    })
}).catch(err => {
    console.log({ err });
});


/* eslint-disable no-new */
// new Vue({
// el: '#app',
// router,
// components: { App },
// template: '<App/>'
// })